package com.ebt.m.data.entity;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;

import com.ebt.m.config.CustomerConfig;
import com.ebt.m.customer.listener.ICustomer;
import com.ebt.m.utils.DataAnnotationCompareExcept;
import com.ebt.m.utils.DateUtils;
import com.ebt.m.utils.ImageUtils;
import com.ebt.m.utils.StringUtils;

import java.io.Serializable;
import java.util.Date;

public class Customer implements Serializable, Cloneable, ICustomer {

    private static final long serialVersionUID = 1L;
    private Long id;
    private String uuid;
    private Integer isDemo;// 是否演示对象
    private String name;// 将firstname和lastname合并
    private String namePrefix;// 名字首字母
    private String portraitPath;// 头像路径
    private Integer sex;// 性别 0女 1 男
    private String level;// 级别
    private String companyName;// 公司名称
    private String jobTitle;// 职位
    private String cellPhone;// 手机
    private String email;// 邮箱
    private Date birthday;// 生日
    private Integer isConfirm;// 生日是否定0否
    private Integer careerCategory;// 职业类别
    private Integer isTopDemo;// 是否置顶
    private String nickname;// 昵称
    private Integer isRegular;// 是否正式客户0非正式1正式
    private String bloodType;// 血型
    private Integer isMarrage;//婚姻状况  未婚0，已婚1，未知2
    private String educationGrading;// 最高学历
    private Integer hasSocialInsurance; // 是否有社保
    private String socialInsuranceRemark; //社保备注
    private String notes; // 描述
    private Integer relationFlag;//是否客户(0否/1是)
    private Integer ChangeStatus;
    private Integer tag;//0:普通客户、1:准客户、2:保单客户

    private String sortKeyString;
    private String sortKeyChar;
    private String importContact;//此标志暂时还没有用到
    private Integer state;//此customer的添加方式，分为“导入”和“新增”,1为导入，空或者0为新增
    private Integer identity;//客户所属的用户账户id

    private Integer relationWith; // 和被保人关系
    private Integer age = -1; // 年龄, 默认-1用于判断
    private String originName; // 原始姓名

    public Integer getIdentity() {
        return identity;
    }

    public void setIdentity(Integer identity) {
        this.identity = identity;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getTag() {
        return tag;
    }

    public void setTag(Integer tag) {
        this.tag = tag;
    }

    @DataAnnotationCompareExcept
    private Date createTime;// 创建事件

    @DataAnnotationCompareExcept
    private Long lastActiveTime2;

    @DataAnnotationCompareExcept
    private Date updateTime;// 更新时间

    public String getSortKeyString() {
        return sortKeyString;
    }

    public void setSortKeyString(String sortKeyString) {
        this.sortKeyString = sortKeyString;
    }

    public String getSortKeyChar() {
        return sortKeyChar;
    }

    public void setSortKeyChar(String sortKeyChar) {
        this.sortKeyChar = sortKeyChar;
    }

    public String getImportContact() {
        return importContact;
    }

    public void setImportContact(String importContact) {
        this.importContact = importContact;
    }

    public Long getLastActiveTime2() {
        return lastActiveTime2;
    }

    public void setLastActiveTime2(Long lastActiveTime2) {
        this.lastActiveTime2 = lastActiveTime2;
    }

    public String getNotes() {
        return notes;
    }

    public Integer getChangeStatus() {
        return ChangeStatus;
    }

    public void setChangeStatus(Integer changeStatus) {
        ChangeStatus = changeStatus;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public Integer getHasSocialInsurance() {
        return hasSocialInsurance;
    }

    public void setHasSocialInsurance(Integer hasSocialInsurance) {
        this.hasSocialInsurance = hasSocialInsurance;
    }

    public String getSocialInsuranceRemark() {
        return socialInsuranceRemark;
    }

    public void setSocialInsuranceRemark(String socialInsuranceRemark) {
        this.socialInsuranceRemark = socialInsuranceRemark;
    }

    public String getEducationGrading() {
        return educationGrading;
    }

    public void setEducationGrading(String educationGrading) {
        this.educationGrading = educationGrading;
    }

    public Integer getRelationFlag() {
        return relationFlag;
    }

    public void setRelationFlag(Integer relationFlag) {
        this.relationFlag = relationFlag;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Integer getIsMarrage() {
        return isMarrage;
    }

    public void setIsMarrage(Integer isMarrage) {
        this.isMarrage = isMarrage;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getBloodType() {
        return bloodType;
    }

    public void setBloodType(String bloodType) {
        this.bloodType = bloodType;
    }

    public Integer getIsRegular() {
        return isRegular;
    }

    public void setIsRegular(Integer isRegular) {
        this.isRegular = isRegular;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Integer getIsTopDemo() {
        return isTopDemo;
    }

    public void setIsTopDemo(Integer isTopDemo) {
        this.isTopDemo = isTopDemo;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getIsDemo() {
        return isDemo;
    }

    public void setIsDemo(Integer isDemo) {
        this.isDemo = isDemo;
    }

    public String getNamePrefix() {
        return namePrefix;
    }

    public void setNamePrefix(String namePrefix) {
        this.namePrefix = namePrefix;
    }

    public String getPortraitPath() {
        return portraitPath;
    }

    public void setPortraitPath(String portraitPath) {
        this.portraitPath = portraitPath;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getJobTitle() {
        return jobTitle;
    }

    public void setJobTitle(String jobTitle) {
        this.jobTitle = jobTitle;
    }

    public String getCellPhone() {
        return cellPhone;
    }

    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Integer getIsConfirm() {
        return isConfirm;
    }

    public void setIsConfirm(Integer isConfirm) {
        this.isConfirm = isConfirm;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getCareerCategory() {
        return careerCategory;
    }

    public void setCareerCategory(Integer careerCategory) {
        this.careerCategory = careerCategory;
    }

    public Integer getRelationWith() {
        return relationWith;
    }

    public void setRelationWith(Integer relationWith) {
        this.relationWith = relationWith;
    }

    /**************
     * Michael 添加
     ****************/

    public String getCustomerId() {
        return uuid;
    }

    public void setCustomerId(String id) {
        this.uuid = id;
    }

    /**
     * 获取年龄
     *
     * @return
     */
    public int getAge() {
        if (age > -1) {
            return age;
        }
        if (this.birthday != null) {
            return com.ebt.m.proposal_v2.utils.DateUtils.getAgeByActualBirthdayWithMonthOriginal(this.birthday);
        }
        return 30;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 职业类别大写 "一", "二", "三", "四", "五", "六"
     *
     * @return
     */
    public String getCareerCategoryCn() {
        if (this.careerCategory == null)
            return "未设定";
        if (this.careerCategory == 0 || this.careerCategory > 6)
            return "数据异常";
        String[] num = new String[]{"零", "一", "二", "三", "四", "五", "六"};

        return num[this.careerCategory];
    }

    public Bitmap getProfile(Context context) {
        Bitmap bitmap = null;
        if (portraitPath != null) {
            bitmap = ImageUtils.decodeFile2Bitmap(portraitPath);
        }
        if (bitmap == null) {
            int age = DateUtils.getAge(birthday);
            int id = CustomerConfig.getPortraitResource(sex, age);
            bitmap = ImageUtils.getBitmapFromDrawable(context, id);
        }
        return bitmap;
    }

    /**
     * @return
     */
    public SpannableString getNameAndNickName() {
        SpannableString ss = null;
        if (StringUtils.isEmpty(nickname)) {
            ss = new SpannableString(name);
        } else {
            ss = new SpannableString(name + " " + nickname);
            int length = name.length() + 1;
            ss.setSpan(new AbsoluteSizeSpan(13, true), length, length
                    + nickname.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return ss;
    }

    /**
     * @return
     */
    public String getAgeAndCategoryCn() {
        StringBuilder builder = new StringBuilder(10);
        if (sex != null && sex == 1) {
            builder.append("男 | ");
        } else {
            builder.append("女 | ");
        }
        builder.append(getAge()).append("岁 | ");
        builder.append(getCareerCategoryCn());
        builder.append("类");
        return builder.toString();
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Customer c = (Customer) super.clone();
        if (birthday != null) {
            c.setBirthday((Date) birthday.clone());
        }
        if (createTime != null) {
            c.setCreateTime((Date) createTime.clone());
        }
        return c;
    }

    @Override
    public String getCustomerUuid() {
        return uuid;
    }

    public String getOriginName() {
        return originName;
    }

    public void setOriginName(String originName) {
        this.originName = originName;
    }

    public void cloneToOriginName() {
        this.originName = this.name;
    }

    public void cloneToName() {
        this.name = this.originName;
    }

    @Override
    public String toString() {
        return "姓名： " + name + "\n"
                + "性别： " + sex + "\n"
                + "年龄： " + age + "\n"
                + "生日： " + birthday;
    }
}